package com.cnaaa.pay.util;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 2018/10/29 Create by 郭文梁
 * RequestParamUtil
 * 请求参数工具
 *
 * @author 郭文梁
 * @date 2018/10/29
 */
public class RequestParamUtil {
    public static Map<String, String> pretty(Map<String, String[]> requestParams) throws UnsupportedEncodingException {
        Map<String, String> params = new HashMap<>(10);
        for (Map.Entry<String, String[]> entry : requestParams.entrySet()) {
            String valueStr = CollectionUtil.join(Arrays.asList(entry.getValue()), ",");
            //出现乱码时使用
            valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
            params.put(entry.getKey(), valueStr);
        }
        return params;
    }

    public static Map<String, String> prettyWithoutCharset(Map<String, String[]> requestParams) {
        Map<String, String> params = new HashMap<>(10);
        for (Map.Entry<String, String[]> entry : requestParams.entrySet()) {
            String valueStr = CollectionUtil.join(Arrays.asList(entry.getValue()), ",");
            //出现乱码时使用
            params.put(entry.getKey(), valueStr);
        }
        return params;
    }
}
